/**
 * SplitCriteria class specifies how a ContextTreeNode may be
 * split into two nodes.  It is used to divide the ContextDataCollection
 * contained within the ContextTreeNode into two separate ContextDataCollection
 * containers which will be part of ContextTreeNode's child nodes.
 * <p>When a split occurs, all the contexts whose bucket index is less than
 * or equal to the split criteria's bucket index is moved to the left child node.
 * All other nodes are moved to the right child node.
 * <p>A split criteria is entirely defined by context id and bucket index. 
 * 
 * @author Yong Shin
 *
 */
public class SplitCriteria implements Comparable<SplitCriteria>{

	/** Context ID of the split context characteristic*/
	private int contextID;
	
	/** Bucket index of the split criteria */
	private int bucketIndex;
		
	public SplitCriteria(int contextID, int bucketIndex) {
		this.contextID = contextID;
		this.bucketIndex = bucketIndex;
	}
	
	public int getContextID() {
		return contextID;
	}
	
	public int getBucketID() {
		return bucketIndex;
	}

        @Override
	    public boolean equals(Object obj) {
	    boolean result = false;
	    if (obj != null) {
		if (obj.getClass() == getClass()) {
		    SplitCriteria sc = (SplitCriteria) obj;
		    return (sc.contextID == contextID) && 
			(sc.bucketIndex == bucketIndex);
		}
	    }
	    return result;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(contextID);
		sb.append(" ");
		
		ContextDefinition ctxdef = ContextDefinition.getContextDefinition();
		Context ctx = ctxdef.getContext(contextID);
		sb.append(ctx.getContextForBucketID(bucketIndex));
		
		return sb.toString();
	}
        
        public int compareTo(SplitCriteria other) {
            if (this.contextID == other.contextID) 
                return this.bucketIndex - other.bucketIndex;
            else return this.contextID - other.contextID;
        }
}
